package com.twu.biblioteca;

public class LibraryService {

    private Library library;
    private static String SUCCESSFUL_CHECK_OUT_BOOK = "Thank you! Enjoy the book.";
    private static String FAILED_CHECK_OUT_BOOK = "That book is not available.";
    private static String SUCCESSFUL_CHECK_OUT_Movie = "Thank you! Enjoy the movie.";
    private static String FAILED_CHECK_OUT_Movie = "That movie is not available.";
    private static String SUCCESSFUL_RETURN_BOOK = "Thank you for returning the book.";
    private static String FAILED_RETURN_BOOK = "That is not a valid book to return.";
    private static String SUCCESSFUL_RETURN_MOVIE = "Thank you for returning the movie.";
    private static String FAILED_RETURN_MOVIE = "That is not a valid movie to return.";

    public LibraryService(Library library) {
        this.library = library;
    }

    public Borrowable checkOutBook(String bookId) {
        Borrowable book =  library.findBook(bookId);
        if(book!=null){
            library.moveBookToBorrowed(book);
        }
        return book;
    }

    public Borrowable checkOutMovie(String movieId) {
        Borrowable movie = library.findMovie(movieId);
        if (movie!=null){
            library.moveMovieToBorrowed(movie);
        }
        return movie;
    }


    public Borrowable returnBook(String bookId) {
        Borrowable book = library.findBorrowedBook(bookId);
        if (book != null){
            library.moveBookToBorrowable(book);
        }

        return book;
    }

    public Borrowable returnMovie(String movieId) {
        Borrowable movie = library.findBorrowedMovie(movieId);
        if(movie != null){
            library.moveMovieToBorrowable(movie);
        }
        return movie;
    }


    public String checkOutBookMsg(Book book) {
        if(book!=null){
            return SUCCESSFUL_CHECK_OUT_BOOK;
        }
        return FAILED_CHECK_OUT_BOOK;
    }

    public String checkOutMovieMsg(Movie movie) {
        if(movie!=null){
            return SUCCESSFUL_CHECK_OUT_Movie;
        }
        return FAILED_CHECK_OUT_Movie;
    }

    public String returnBookMsg(Book book) {
        if (book!=null){
            return SUCCESSFUL_RETURN_BOOK;
        }
        return FAILED_RETURN_BOOK;
    }

    public String returnMovieMsg(Movie movie) {
        if (movie != null){
            return SUCCESSFUL_RETURN_MOVIE;
        }
        return FAILED_RETURN_MOVIE;
    }
}
